﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;

namespace StevensReceipts.Domain
{
    /// <summary>
    /// A business is a gst registered/un-registered business unit.
    /// A registered Client can register many businesses under the client account
    /// </summary> 
    public class Business : IEntity
    {
        public Business()
        {
            GstRegistered = false;
            FinancialYearEndDay = 0;
            FinancialYearEndMonth = 0;
            Created = DateTime.Now;
        }

        [Key]
        public int Id { get; set; }

        [StringLength(255)]
        public string BusinessName { get; set; }

        [StringLength(255)]
        public string BusinessCountry { get; set; }

        [StringLength(255)]
        public string TradingName { get; set; }

        /// <summary>
        /// type of business form
        /// </summary>
        public BusinessType Type { get; set; }

        /// <summary>
        /// business description brief
        /// </summary>
        [StringLength(255)]
        public string BusinessLine { get; set; }

        public bool GstRegistered { get; set; }

        //financial details
        
        public int FinancialYearEndDay { get; set; }

        
        public int FinancialYearEndMonth { get; set; }

        public GstPeriod GstPeriod { get; set; }

        [StringLength(11)]
        public string GstNumber { get; set; }

        public GstBasis GstBasis { get; set; }

        /// <summary>
        /// the list of chart of accounts for this business
        /// </summary>
        [JsonIgnore]
        public virtual ICollection<ChartofAccount> ChartOfAccounts { get; set; }

        /// <summary>
        /// all the contacts associated with this business (having business with this business entity)
        /// </summary>
        [JsonIgnore]
        public virtual ICollection<Contact> Contacts { get; set; }

        public virtual Address PhysicalAddress { get; set; }

        public virtual Address PostalAddress { get; set; }

        [StringLength(50)]
        public string ContactPerson { get; set; }


        public string Telephone { get; set; }

        public string Mobile { get; set; }

        public string Fax { get; set; }

        [JsonIgnore]
        public virtual ICollection<UserPermissionLine> UserPermissions { get; set; } 


        public DateTime? Created { get; set; }

        public DateTime? Modified { get; set; }
    }


    public enum GstPeriod
    {
        [Description("1 Monthly")]
        OneMonthly,
        [Description("2 Monthly")]
        TwoMonthly,
        [Description("6 Monthly")]
        SixMonthly
    }

    public enum GstBasis
    {
        [Description("Payment Basis")]
        Payments_Basis,
        [Description("Invoice Basis")]
        Invoice_Basis,
        [Description("None")]
        None
    }
}